package demo4;
//Object类




public class Test {
    public static void main(String[] args) {
        Person person1 = new Person("zhangsan");
        Person person2 = new Person("zhangsan");

        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }
    public static void main2(String[] args) {
        //重写equals
        Person person1 = new Person("zhangsan");
        Person person2 = new Person("zhangsan");

        System.out.println(person1==person2);//引用类型，比较的是地址（哈希值）

        System.out.println(person1.equals(person2));//未重写equals时,调用的是Oject的,也是比较地址

        String str1 = "zhangsan";
        String str2 = "zhangsan";
        System.out.println(str1.equals(str2));//String重写了equals方法

    }
    public static void main1(String[] args) {
        //重写toString
        Person person = new Person("李四");
        //Object object = person;//向上转型
        System.out.println(person.name);

    }
}
